package cn.wolfcode.trip.base.service.impl;

import cn.wolfcode.trip.base.domain.MyCollection;
import cn.wolfcode.trip.base.mapper.MyCollectionMapper;
import cn.wolfcode.trip.base.query.MyCollectionQueryObject;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.service.IMyCollectionService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class MyCollectionServiceImpl implements IMyCollectionService {
    @Autowired
    private MyCollectionMapper collectionMapper;

    public void save(MyCollection collection) {
        //设置创建时间
        collection.setCollectTime(new Date());
        collectionMapper.insert(collection);
    }

    public PageInfo query(MyCollectionQueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(), qo.getPageSize());
        return new PageInfo(collectionMapper.query(qo));
    }

    public void delete(Long strategydetailId, Long travelId, Long dailyId, Long userId) {
        collectionMapper.deleteByThreeIdAndUserId(strategydetailId, travelId, dailyId, userId);
    }

    public Boolean checkHasCollection(Long strategydetailId, Long travelId, Long dailyId, Long userId) {
        if (strategydetailId != null || travelId != null || dailyId != null) {
            Integer count = collectionMapper.selectByThreeIdAndUserId(strategydetailId, travelId, dailyId, userId);
            if (count > 0) {
                return true;
            }
        }
        return false;
    }

    @Override
    public Integer selectCollection(QueryObject qo) {
        return collectionMapper.selectCollection(qo);
    }

    @Override
    public Integer selecttravelId(MyCollectionQueryObject qo) {
        return collectionMapper.selecttravelId(qo);
    }

    @Override
    public Integer selectstrategydetaiId(MyCollectionQueryObject qo) {
        return collectionMapper.selectstrategydetaiId(qo);
    }

    @Override
    public Integer selectdailyId(MyCollectionQueryObject qo) {
        return collectionMapper.selectdailyId(qo);
    }
}
